package service

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"wechat-moments_0926/internal/model"
	"wechat-moments_0926/internal/params"
)

func AddLike(c *gin.Context) {
	var req params.AddLikeForm

	if err := c.ShouldBindJSON(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    100000,
			"message": "验证失败",
			"data":    "",
		})
		return
	}

	var like model.Like

	like = model.Like{
		FeedId: req.UserId,
		UserId: req.UserId,
	}

	err := like.AddLike()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    100000,
			"message": "点赞失败",
			"data":    err.Error(),
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "点赞成功",
		"data":    like.Id,
	})
}
